<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 600px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb clearfix">

      <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>inbody数据报表-过滤查询</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/inbody-reports/search" data-validate = "true">
      <input type="hidden" name="_method" value="PATCH">

      <div class="modal-body">
      
        <c:if test="${currentPrincipal.admin or currentPrincipal.root}">
          <div class="form-group x-form-group">
            <label class="col-xs-4 control-label">门店</label>
            <div class="col-xs-6" style="width: 50%;">
              <select name="site" class="form-control select2" data-validate = "required">
                <option value="">全部门店</option>
                <c:forEach var="site" items="${persist.sites}">
                  <option value="${site.id}" ${site.id == selectedSiteId ? 'selected' : ''}>${site.name}</option>
                </c:forEach>
              </select>
            </div>
          </div>
        </c:if>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">学员手机号</label>
          <div class="col-xs-6" style="width: 50%;">
            <input type="text" class="form-control" name="mobile" value="${mobile}" placeholder="学员手机号"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">教练</label>
          <div class="col-xs-6" style="width: 50%;">
            <select name="coach" class="form-control" data-validate="required">
              <option value=""></option>
              <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, param.site)}">
                <c:if test="${principal.value.coach}">
                  <option value="${principal.key}" ${selectedCoachId == principal.key ? 'selected' : ''}>${principal.value.name}</option>
                </c:if>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">测试时间</label>
          <div class="col-xs-6" style="width: 50%;">
            <div class="input-group">
              <input type="text" class="form-control date" name="from" value="${from}" placeholder="开始时间"/>
              <span class="input-group-addon"></span>
              <input type="text" class="form-control date" name="to" value="${to}" placeholder="结束时间"/>
            </div>
          </div>
        </div>
        
      </div>

      <div class="modal-footer">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>

    </form>

  </div>

</div>

<script type="text/javascript">
  $(function() {
    
    $('.date').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month',
        startDate: '2015-08-18',
        endDate: '${today}'
      });
    
    $('select[name="site"]').select2({
      minimumResultsForSearch : -1,
      allowClear : false
     });
    
    $('select[name="coach"]').select2({
      minimumResultsForSearch : 5,
      allowClear : true
      });
  })
</script>
